package com.hxx.day4;

import org.junit.Test;

public class TestDemo4 {
    public static void main(String...args) {
        int[][] arr = new int[2][2];
        arr[0][0] = 1;
        arr[0][1] = 2;
        arr[1][0] = 3;
        arr[1][1] = 4;
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                System.out.print("arr["+i+"]["+j+"]="+arr[i][j] + "\t");
            }
            System.out.println();
        }
    }

    @Test
    public void test1() {
        int[][] arr = {{1},{2,3},{4,5,6}};
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                System.out.println("arr["+i+"]["+j+"]="+arr[i][j] + "\t");
            }
            System.out.println("---------------------");
        }
    }
    //高维数组创建
    @Test
    public void test2() {
        //创建数组的时候不确定列的数量
        int[][] arr = new int[3][];
        //使用时确定列的数量
        arr[0] = new int[2];
        arr[1] = new int[3];
        arr[2] = new int[4];

        arr[0][0] = 1;
        arr[0][1] = 2;
        arr[1][0] = 3;
        arr[1][1] = 4;
        arr[1][2] = 5;
        arr[2][0] = 6;
        arr[2][1] = 7;
        arr[2][2] = 8;
        arr[2][3] = 9;
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                System.out.println("arr["+i+"]["+j+"]="+arr[i][j] + "\t");
            }
            System.out.println("---------------------");
        }
    }

    /**
     * 可变参数只能出现一次，并且，在所有参数的最后一个位置
     * @param i
     */
    public void show(int...i){
        System.out.println(i.length);
    }

    public void show(int i){
        System.out.println(i);
    }
    @Test
    public void test3() {
        //一定是执行精确的方法，否则才去执行可变参数的方法
        show(10);
    }
}




















